﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Apps.IBLL;
using Apps.Models.Sys;
using Unity.Attributes;
using Apps.Common;

namespace Apps.Web.Controllers
{
	public class SysSampleController : Controller
	{
		// GET: SysSample
		[Dependency]
		public ISysSampleBLL sampleBLL { get; set; }
		public ActionResult Index()
		{
			return View();
		}
		[HttpPost]
		public JsonResult GetList(GridPager gridPager)
		{
			List<SysSampleModel> list = sampleBLL.GetList(ref gridPager);
			var json = new
			{
				total = gridPager.totalPages,
				rows = (from r in list
						select new SysSampleModel()
						{
							Id = r.Id,
							Name = r.Name,
							Age = r.Age,
							Bir = r.Bir,
							Photo = r.Photo,
							Note = r.Note,
							CreateTime = r.CreateTime,
						}).ToArray()
			};
			return Json(json, JsonRequestBehavior.AllowGet);
		}

		#region 创建
		public ActionResult Create()
		{
			return View();
		}

		[HttpPost]
		public JsonResult Create(SysSampleModel model)
		{

			if (sampleBLL.Create(model))
			{
				return Json(1, JsonRequestBehavior.AllowGet);
			}
			else
			{
				return Json(0, JsonRequestBehavior.AllowGet);
			}

		}
		#endregion

		#region 修改

		public ActionResult Edit(string id)
		{

			SysSampleModel entity = sampleBLL.GetById(id);
			return View(entity);
		}

		[HttpPost]
		public JsonResult Edit(SysSampleModel model)
		{
			if (sampleBLL.Edit(model))
			{
				return Json(1, JsonRequestBehavior.AllowGet);
			}
			else
			{
				return Json(0, JsonRequestBehavior.AllowGet);
			}

		}
		#endregion

		#region 详细
		public ActionResult Details(string id)
		{
			SysSampleModel entity = sampleBLL.GetById(id);
			return View(entity);
		}

		#endregion

		#region 删除
		[HttpPost]
		public JsonResult Delete(string id)
		{
			if (!string.IsNullOrWhiteSpace(id))
			{
				if (sampleBLL.Delete(id))
				{
					return Json(1, JsonRequestBehavior.AllowGet);
				}
				else
				{

					return Json(0, JsonRequestBehavior.AllowGet);
				}
			}
			else
			{
				return Json(0, JsonRequestBehavior.AllowGet);
			}


		}
		#endregion

	}
}